<style>
	.bold {
		font-weight: bold;
	}
</style>
<?php
	if(!empty($_GET['nama'])){
		$param_nama=$_GET['nama'];
	}else{
		$param_nama=$_POST['nama'];
	}
?>
<div class="judul_content">Laporan Penjualan</div>

<form method="post" action="utama.php?module=mod_order">
	<table class="tbl_cari">
		<tr>
			<td width="65">Pencarian  : </td>
			<td width="200"><input type="text" name="nama" value="<?php echo $param_nama; ?>" class="frm_cari" /></td>
			<td><input name="submit" type="submit" class="submit" value="Cari" /></td>
			<td></td>
			<td align="right"></td>
		</tr>
	</table>
</form>

<table class="table" border="1">
    <tr>
        <th width="20">No</th>
		<th>Tanggal</th>
		<th>ID Order</th>
		<th>Nama</th>
		<th>Alamat</th>
		<th>Resi</th>
		<th>Total</th>
        <th width="50">Aksi</th>
    </tr>
    <?php
    	$p= new paging ;
		$batas= 10;

		//cek halaman dan posisi halaman
		$posisi = $p ->cariposisi($batas) ;

    	$sttmt = $koneksi->query("select * from orders o inner join status s on o.id_status = s.id_status where o.nama_konsumen like '%$param_nama%' order by tgl_order desc, id_orders asc limit $posisi,$batas");
    	$no = $posisi + 1;

		while($hasil = $sttmt->fetch(PDO::FETCH_ASSOC)){
			if($hasil['id_status'] != 1){
				$bold = "class = bold";
			}else{
				$bold = "";
			}
    		?>
		    <tr <?php echo $bold;?>>
		        <td><?php echo $no; ?></td>
				<td><?php echo $hasil['tgl_order']; ?></td>
		        <td><?php echo $hasil['id_orders']; ?></td>
				<td><?php echo $hasil['nama_konsumen']; ?></td>
				<td><?php echo $hasil['alamat']; ?></td>
				<td><?php echo $hasil['resi']; ?></td>
				<td>
					<?php  
						$total = $koneksi->query("select sum(harga*jumlah) as subtotal, sum(harga*jumlah*diskon/100) as diskon from order_detail where id_orders = '$hasil[id_orders]'");
						$t = $total->fetch(PDO::FETCH_ASSOC);
						$total = $t['subtotal'] - $t['diskon'];
						echo harga($total);
					?>
				</td>
		        <td>
		        	<a href="utama.php?module=mod_order&view=detail&id=<?php echo $hasil['id_orders']; ?>">
						<img src="asset/images/detail.png" title="Edit">
					</a>
		        	<a href="utama.php?module=mod_order&view=form_edit&id=<?php echo $hasil['id_orders']; ?>">
						<img src="asset/images/edit.png" title="Edit">
					</a>
		        	<a href="utama.php?module=mod_order&act=hapus&id=<?php echo $hasil['id_orders']; ?>" onclick="return confirm('Anda yakin ingin Menghapus Data ?')">
		        		<img src="asset/images/delete.png" title="Hapus">
		        	</a>
		        </td>
		    </tr>
    		<?php
    		$no++;
		}
	?>
</table>
<br>
<?php
	$sttmt = $koneksi->query("select * from orders where nama_konsumen like '%$param_nama%' order by tgl_order desc");
	$jumlah_data = $sttmt->rowCount();
	//dapatkan jumlah halaman
	$jumlah_halaman= $p->jumlahhalaman($jumlah_data,$batas);
	//cetak link
	$linkhalaman=$p->navhalaman($_GET['halaman'],$jumlah_halaman,$_SERVER['PHP_SELF']."?module=mod_order","nama=$param_nama");
	print($linkhalaman);
?>
        